
load('summary_data/fig6.rda')

x_l = c('[0,90)','[90,95)','[95,99)','[99,99.5)','[99.5,99.9)','[99.9,)')

ga = rbindlist(list(r12a, r16a, r20a)) %>%
  ggplot(aes(
    x = nat_quant_col,
    y = sq,
    fill = class,
    group = class,
    color = class,
    shape = class
  )) +
  geom_point() + geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_y_continuous(labels = scales::label_percent(), limits = c(0, .6)) +
  labs(
    x = element_blank(),
    y = element_blank(),
    fill = element_blank(),
    shape = element_blank(),
    title = 'GOP Primary Donor Conversion'
  ) +
  scale_fill_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  scale_color_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  scale_shape_manual(values = c(15, 17, 19)) +
  theme(
    legend.position = 'top',
    axis.text.x = element_text(
      angle = 25,
      vjust = .8,
      hjust = 0.5,
      size = 8
    )
  ) +
  guides(fill = 'none',
         color = guide_legend(title = element_blank(), ncol = 1)) +
  theme(text = element_text(face = 'bold'))

gb = rbindlist(list(r12b, r16b, r20b)) %>%
  ggplot(aes(
    x = nat_quant_col,
    y = sq,
    fill = class,
    group = class,
    color = class,
    shape = class
  )) +
  geom_point() +
  geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_y_continuous(labels = scales::label_percent(), limits = c(0, .6)) +
  labs(
    x = element_blank(),
    y = element_blank(),
    fill = element_blank(),
    shape = element_blank(),
    title = 'GOP Congressional Cross-Cycle Retention'
  ) +
  scale_fill_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  scale_color_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  scale_shape_manual(values = c(15, 17, 19)) +
  theme(
    legend.position = 'top',
    axis.text.x = element_text(
      angle = 25,
      vjust = .8,
      hjust = 0.5,
      size = 8
    )
  ) +
  guides(fill = 'none',
         color = guide_legend(title = element_blank(), ncol = 1)) +
  theme(text = element_text(face = 'bold'))

out = plot_grid(
  ga,
  gb,
  nrow = 1,
  labels = str_c('(', LETTERS[1:2], ')'),
  label_x = -.025,
  label_y = 1
)

ggsave(filename = 'figures/fig6.pdf', plot = out, width = 9, height = 4, units = 'in')
